//
//  THJBaozhengjinVC.m
//  THJXHW
//
//  Created by 河南德艺 on 2018/8/11.
//  Copyright © 2018年 河南德艺. All rights reserved.
//

#import "THJBaozhengjinVC.h"

@interface THJBaozhengjinVC ()
{
    NSDictionary * infoDic;
}
@end

@implementation THJBaozhengjinVC

- (void)viewDidLoad {
    [super viewDidLoad];
    if(KIsiPhoneX){
        [self setXNavBarWithTitle:@"交保证金"];
    }else{
        [self setNavBarWithTitle:@"交保证金"];
    }
    [self getData];
    // Do any additional setup after loading the view from its nib.
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}
- (IBAction)sureBtnAction:(id)sender {
    
    if(self.tf1.text.length == 0){
        [self HUDShowMsg:@"输入金额" AfterDelayDimiss:1];
        return;
    }else if(self.tf2.text.length == 0){
        [self HUDShowMsg:@"输入支付密码" AfterDelayDimiss:1];
        return;
    }
    
    NSString * mobile = [RSA encryptString:[THJTools getMobile] publicKey:RSA_PubKey];
    NSString * money = [RSA encryptString:self.tf1.text publicKey:RSA_PubKey];
    NSString * pwd = [RSA encryptString:self.tf2.text publicKey:RSA_PubKey];
    [self SVHUDShow];
    [THJNetWork postNetDataFromUrl:@"http://p.thjb.net/thjblink/appdata.php?action=pay_bond_ok" parameters:@{@"mobile":mobile,@"type":@"ios",@"pwd":pwd,@"money":money} callback:^(NSDictionary *  receiveData, NSError*error) {
        NSLog(@"交保证金--%@",receiveData);
        [self SVHUDHiden];
        if([receiveData[@"status"] isEqual:@"success"]){
            [self HUDShowMsg:@"交保证金成功" AfterDelayDimiss:1];
            self.tf1.text = @"";
            self.tf2.text = @"";
            [self getData];
        }else{
            NSString * tip = [RSA decryptString:receiveData[@"data"] publicKey:RSA_PubKey];
            [self HUDShowMsg:tip AfterDelayDimiss:2];
        }
    }];
}
-(void)getData{
    [self SVHUDShow];
    NSString * mobile = [RSA encryptString:[THJTools getMobile] publicKey:RSA_PubKey];
    [THJNetWork postNetDataFromUrl:@"http://p.thjb.net/thjblink/appdata.php?action=hjb_dj" parameters:@{@"mobile":mobile,@"type":@"ios"} callback:^(NSDictionary *  receiveData, NSError *error) {
        NSLog(@"交保证金--%@",receiveData);
        [self SVHUDHiden];
        if([receiveData[@"status"] isEqual:@"success"]){
            NSLog(@"money-%@",[RSA decryptString:receiveData[@"data"][@"money"] publicKey:RSA_PubKey]);
            NSLog(@"ymoney-%@",[RSA decryptString:receiveData[@"data"][@"yMoney"] publicKey:RSA_PubKey]);
            NSLog(@"nmoney-%@",[RSA decryptString:receiveData[@"data"][@"nMoney"] publicKey:RSA_PubKey]);
            self.lab2.text = [RSA decryptString:receiveData[@"data"][@"money"] publicKey:RSA_PubKey];
            self.lab1.text = [RSA decryptString:receiveData[@"data"][@"yMoney"] publicKey:RSA_PubKey];
            self.lab3.text = [RSA decryptString:receiveData[@"data"][@"nMoney"] publicKey:RSA_PubKey];
        }else{
            [self HUDShowMsg:[RSA decryptString:receiveData[@"data"] publicKey:RSA_PubKey] AfterDelayDimiss:1];
        }
    }];
}
@end
